// Content for the theoretical analysis section
document.addEventListener('DOMContentLoaded', function() {
    // Populate Economic Principles column
    document.querySelector('#analysis .column:first-child .content-box').innerHTML = `
        <h4>Law of Diminishing Marginal Utility</h4>
        <p>The Jia family's experience perfectly demonstrates how each additional unit of consumption provides decreasing satisfaction. Their continued high spending on luxury items and entertainment yielded progressively less utility over time.</p>

        <h4>Opportunity Cost</h4>
        <p>Resources allocated to maintaining social status through lavish celebrations and garden maintenance could have been invested in sustainable ventures. The family's failure to recognize these opportunity costs contributed to their decline.</p>

        <h4>Economic Sustainability</h4>
        <p>The imbalance between income and expenditure, coupled with the failure to maintain productive assets, led to the gradual erosion of the family's wealth. Their focus on consumption over investment proved unsustainable.</p>

        <h4>Resource Allocation Theory</h4>
        <p>The family's resource distribution heavily favored status maintenance over economic efficiency, leading to suboptimal allocation and eventual economic strain.</p>
    `;

    // Populate Novel Examples column
    document.querySelector('#analysis .column:nth-child(2) .content-box').innerHTML = `
        <h4>Grand View Garden</h4>
        <p>Initially brought immense satisfaction and prestige, but its maintenance became a significant burden. The declining utility is evident in its later neglect and deterioration.</p>

        <h4>Household Management</h4>
        <p>The extensive staff initially provided essential services and status, but eventually led to management complications and inefficiencies, demonstrating diminishing returns in household operations.</p>

        <h4>Social Celebrations</h4>
        <p>Early celebrations generated substantial social capital, but later events yielded decreasing returns while maintaining high costs, illustrating the principle of diminishing marginal utility in social investments.</p>

        <h4>Luxury Consumption</h4>
        <p>The family's continued high spending on luxury items despite declining satisfaction exemplifies their failure to recognize and adapt to diminishing returns.</p>
    `;

    // Add interactive elements to principle cards
    document.querySelectorAll('.principle-card').forEach(card => {
        card.addEventListener('mouseenter', function() {
            this.style.transform = 'translateY(-5px)';
            this.style.boxShadow = '0 4px 8px rgba(0,0,0,0.2)';
        });

        card.addEventListener('mouseleave', function() {
            this.style.transform = 'translateY(0)';
            this.style.boxShadow = '0 2px 4px rgba(0,0,0,0.1)';
        });
    });

    // Add citation tooltips
    const citations = document.querySelectorAll('.citation');
    citations.forEach(citation => {
        const tip = document.createElement('div');
        tip.className = 'tooltip';
        tip.textContent = citation.getAttribute('data-source');
        citation.appendChild(tip);
    });
});

// Handle content visibility on scroll
const observerOptions = {
    threshold: 0.2,
    rootMargin: '0px 0px -50px 0px'
};

const contentObserver = new IntersectionObserver(entries => {
    entries.forEach(entry => {
        if (entry.isIntersecting) {
            entry.target.classList.add('visible');
            contentObserver.unobserve(entry.target);
        }
    });
}, observerOptions);

document.querySelectorAll('.content-box').forEach(box => {
    contentObserver.observe(box);
});